//
//  GameOrderCell.swift
//  XiaoJingMallSwift
//
//  Created by beisheng03 on 2017/9/6.
//  Copyright © 2017年 beisheng. All rights reserved.
//

import UIKit

protocol GameOrderCellDelegate : NSObjectProtocol {
    func payBtnDidTap(model : GameOrderModel)
}

class GameOrderCell: BaseTableViewCell {
    
    @IBOutlet weak var leftImageView: UIImageView!
    
    @IBOutlet weak var leftLabel: UILabel!
    
    @IBOutlet weak var initorView: UIActivityIndicatorView!
    
    @IBOutlet weak var prieLabel: UILabel!
    
    @IBOutlet weak var bottomLabel: UILabel!
    
    @IBOutlet weak var payBtn: UIButton!
    
    weak var delegate : GameOrderCellDelegate?
    
    var model : GameOrderModel?{
    
        didSet{
        
            if model == nil {
                return
            }
            
            initorView.startAnimating()
            leftImageView.sd_setImage(with: URL(string :model!.goods_image_url), placeholderImage: UIImage.defaulLogoImage(), options: []) { (image, _, _, _) in
                self.initorView.stopAnimating()
                
                
            }
            
            leftLabel.text = model?.goods_name
            
            if let temp  = model?.goods_price {
                
                prieLabel.text = "¥ \(temp)"

            }
            
            if let temp1 = model?.goods_num {
                bottomLabel.text = "X \(temp1)"
            }
            

        payBtn.setTitle(model?.state_desc, for: .normal)
        
        }
    
    
    }


    override func awakeFromNib() {
        super.awakeFromNib()
        
        payBtn.addCornerAndBorder(borderColor: UIColor.red, borderWidth: 0.6, masksToBounds: true, cornerRadius: 5)

        // Initialization code
    }

    @IBAction func payBtnDidTap(_ sender: UIButton) {
        
        delegate?.payBtnDidTap(model: model!)
        
        
    }
    
    
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
